<template>
  <div class="content-box">
    <nav-title title="社保及个人档案信息" />
    <div class="line">
      <span class="important"></span>
      <div class="label">账户类型</div>
      <div class="value">
        {{socsec.cDescr[0]}}
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">未参加过</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="lcList" v-model="socsec.cYesNo[0]"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">账号</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="socsec.gpcnAcountNum[0]">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">原缴纳地</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="socsec.cAddress[0]">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">状态</div>
      <div class="value">
      <group label-width="5em">
        <popup-radio placeholder="请选择" :options="staVal" v-model="socsec.cPhfStatus[0]"></popup-radio>
      </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">账户类型</div>
      <div class="value">
        {{socsec.cDescr[1]}}
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">未参加过</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="lcList" v-model="socsec.cYesNo[1]"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">账号</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="socsec.gpcnAcountNum[1]">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">原缴纳地</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="socsec.cAddress[1]">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">状态</div>
      <div class="value">
      <group label-width="5em">
        <popup-radio placeholder="请选择" :options="staVal" v-model="socsec.cPhfStatus[1]"></popup-radio>
      </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">账户类型</div>
      <div class="value">
        {{socsec.cDescr[2]}}
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">未参加过</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="lcList" v-model="socsec.cYesNo[2]"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">账号</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="socsec.gpcnAcountNum[2]">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">原缴纳地</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="socsec.cAddress[2]">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">状态</div>
      <div class="value">
      <group label-width="5em">
        <popup-radio placeholder="请选择" :options="staVal" v-model="socsec.cPhfStatus[2]"></popup-radio>
      </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">个人档案所在地</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="basicInfo.cArchiveAddr">
      </div>
    </div>

    <div class="bsbtn" @click="saveall">
      保存
    </div>
  </div>

</template>

<script>
import { Group, PopupRadio  } from 'vux'
import { getDicItem,saveSocial,getQrmsg,saveBsinfo } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    Group, PopupRadio 
  },
  mounted(){
    //获取字典
    this.getstaDic()
    this.getBsInfo()
  },
  created() {
    this.getSocs()
    if(this.$store.state.hid){
      this.socsec.rsHireId = this.$store.state.hid
      this.empid = this.$store.state.hid
    }
  },
  data() {
    return {
      basicInfo:'',
      socsec:{
        rsHireId: '',
        cDescr: ['社会保险','住房公积金','补充住房公积金'],
        cYesNo: ['','',''],
        gpcnAcountNum: ['','',''],
        cAddress: ['','',''],
        cPhfStatus: ['','',''],
        cSeqno: ['','','']
      },
      oldadd: '',
      staVal:[],
      lcList: [{value: '是', key: 'Y'},{value: '否', key: 'N'}],
    }
  },
  methods: {
      //状态
      getstaDic(){
        this.sexVal = []
        let params = {
          fileName: 'C_PHF_STATUS'
        }
        getDicItem(params).then(res => {
          res.retData.forEach((val) => {
            this.staVal.push({value: val.xlatshortname, key: val.fieldvalue})
          });
        }).catch(res => {

        })
      },
    saveall() {
      this.savesoc()
    },
    savesoc() {
      saveSocial(json2Form(this.socsec)).then(res => {
        console.log(res)
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          if(this.oldadd != this.basicInfo.cArchiveAddr){
            this.saveda()
          }else{
            this.$vux.alert.show({
              title: '提示',
              content: '保存成功',
              onHide () {
                that.$router.push('/informationCollection/userInfo');
              }
            })
          }

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })
    },

    saveda() {
      var that = this
      if(that.basicInfo.firstName == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请先录入基本信息'
        });
        return;
      }

      saveBsinfo(json2Form(that.basicInfo)).then(res => {
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })
    },

    getSocs() {
      if(this.$route.params.socvl[0].cSeqno[0]){
        this.socsec = this.$route.params.socvl[0]
      }
    },
    getBsInfo() {
        let params = {rsHireId: this.empid}
        getQrmsg(params).then(res => {
          if (res && res.retCode === '000000') {
            this.basicInfo = res.retData
            this.oldadd = res.retData.cArchiveAddr
          } else {
            alert(res.retMsg);
          }
        })
      },
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
</style>
